﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using LGE;

namespace YouOnlyGetOne
{
    public class UserInterface
    {
        PlayScreen ps;
        Texture2D ui;
        Texture2D grey; // olho1UI_38x38.png
        Texture2D red; // bocaUI_47x47.png
        Texture2D purple; // olho2UI_38x38.

        double uiTimer = 0;
        int uiInterval = 2300;
        int uiMinInterval = 100;
        int uiFrame = 0;

        //ss
        int nFrames = 12;
        int frameDuration = 100;
        double frameTimer = 0;
        int keyFrame = 0;


        public UserInterface(PlayScreen ps)
        {
            this.ps = ps;
            ui = Engine.Load<Texture2D>("Images\\UI\\UI");
            red = Engine.Load<Texture2D>("Images\\UI\\red");
            grey = Engine.Load<Texture2D>("Images\\UI\\grey");
            purple = Engine.Load<Texture2D>("Images\\UI\\purple");
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            uiTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (uiTimer > uiInterval) { uiTimer = 0; uiFrame = uiFrame == 0 ? 1 : 0; uiInterval -= 50; if (uiInterval < uiMinInterval) uiInterval = uiMinInterval; }
            frameTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (frameTimer > frameDuration) { frameTimer = 0; keyFrame++; if (keyFrame >= nFrames) keyFrame = 0; }

            //spriteBatch.DrawString(YOGO.Font, player.position.X + " " + player.position.Y, Vector2.Zero, Color.White);
            /*spriteBatch.DrawString(YOGO.Font34, "Coins: " + ps.player.coins.ToString(), Vector2.Zero, Color.White);
            spriteBatch.DrawString(YOGO.Font34, "Points: " + ps.player.points.ToString(), new Vector2(0, 35), Color.White);
            spriteBatch.DrawString(YOGO.Font34, "Keys: " + ps.player.keys.ToString(), new Vector2(0, 70), Color.White);
            spriteBatch.DrawString(YOGO.Font34, "Time: " + (ps.timer / 1000).ToString("0,0"), new Vector2(0, 105), Color.White);*/

            spriteBatch.Draw(ui, new Vector2(1088, 528), Color.White);
            spriteBatch.Draw(red, new Vector2(1152, 592), new Rectangle(uiFrame * red.Width / 2, 0, red.Width / 2, red.Height), Color.White);
            spriteBatch.Draw(grey, new Vector2(1167, 552), new Rectangle(uiFrame * grey.Width / 2, 0, grey.Width / 2, grey.Height), Color.White);
            spriteBatch.Draw(purple, new Vector2(1105, 614), new Rectangle(uiFrame * purple.Width / 2, 0, purple.Width / 2, purple.Height), Color.White);

            spriteBatch.DrawString(YOGO.Font34, ps.player.keys.ToString() + "x", new Vector2(1223, 517), new Color(197, 197, 197));
            spriteBatch.DrawString(YOGO.Font42, ps.player.points.ToString(), new Vector2(ps.player.points < 0 ? 1160 : 1212, 619), ps.player.points < 0 ? new Color(166, 0, 2) : new Color(255, 246, 0));
            spriteBatch.DrawString(YOGO.Font36, ps.player.coins.ToString(), new Vector2(1191, 675), new Color(64, 60, 54));
            spriteBatch.DrawString(YOGO.Font36, (ps.timer / 1000).ToString("0,0"), new Vector2(1109, 552), new Color(30, 60, 12));
            spriteBatch.Draw(Key.Texture, new Vector2(1209, 551), new Rectangle(keyFrame * Key.Texture.Width / nFrames, 0, Key.Texture.Width / nFrames, Key.Texture.Height), Color.White);
        }
    }
}